FROM centos:7

ENV PATH /usr/local/mysql/bin:$PATH

RUN set -eux; \
	groupadd mysql;\
	useradd mysql --system -g mysql;\
	\
	mkdir -p /var/lib/mysql /var/log/mariadb; \
	chown -R mysql:mysql /var/lib/mysql /var/log/mariadb; \
	echo "" > /var/log/mariadb/mariadb.log;\
	chmod -R 777 /var/lib/mysql /var/log/mariadb; \
	\
	mkdir -p /docker-entrypoint-initdb.d;\
	echo -e "[kunpeng]\nname=CentOS-kunpeng - Base - mirrors.huaweicloud.com\nbaseurl=https://mirrors.huaweicloud.com/kunpeng/yum/el/7/aarch64/\ngpgcheck=0\nenabled=1" > /etc/yum.repos.d/CentOS-Base-kunpeng.repo;\
    yum install -y libaio mysql-5.7.27-1.el7.aarch64 --enablerepo=kunpeng;

COPY docker-entrypoint.sh /usr/local/bin/
  
RUN set -eux; \
	echo -e '[mysqld]\ndatadir=/var/lib/mysql\nsocket=/var/lib/mysql/mysql.sock\nsymbolic-links=0\nlog-error=/var/log/mariadb/mariadb.log\n[mysqld_safe]\nlog-error=/var/log/mariadb/mariadb.log\npid-file=/var/run/mariadb/mariadb.pid\n[client]\nsocket=/var/lib/mysql/mysql.sock' > /etc/my.cnf;\
  chmod 644 /etc/my.cnf;\
  chmod -R 777 docker-entrypoint-initdb.d;\
	chmod 777 /usr/local/bin/docker-entrypoint.sh;\
	mysqld --version; \
	mysql --version

VOLUME /var/lib/mysql
ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 3306 33060
CMD ["mysqld"]
